package examen2;

public class OrdenamientoInsercion {

	public void ordenar(int[] vector) {
		int longitud = vector.length - 1;

		if (longitud > 0) {
			for (int i = 1; i <= longitud; i++) {		
				int auxiliar = vector[i];

				if (vector[i] < vector[i - 1]) {
					int j = 0;
					while (j < i && vector[i] > vector[j]) {
						j++;
					}

					for (int k = i; k > j; k--) {
						vector[k] = vector[k - 1];
					}
					vector[j] = auxiliar;
				}
			}
		}

	}

	public void ordenarNoFunciona(int[] vector) {
		int indiceSubVectorOrdenado = 0;
		int longitud = vector.length - 1;

		for (int i = indiceSubVectorOrdenado + 1; i < longitud; i++) {

			int j = 0;
			int auxiliar = vector[i];

			while (j <= indiceSubVectorOrdenado && vector[i] < vector[j]) {
				j++;
			}

			for (int k = i; k > j; k--) {
				vector[k] = vector[k - 1];
			}
			vector[j] = auxiliar;
		}

	}

	public void intercambiarPosiciones(int[] vector, int i, int j) {
		int auxiliar = vector[i];
		vector[i] = vector[j];
		vector[j] = auxiliar;
	}
}
